# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：deal_idCard.py
#日期：2019-09-26
#备注：生成虚拟身份证,并使用到别的地方
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

weight_code = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]   # Wi代表前17位第i位上的加权因子

check_code = {0:'1', 1:'0', 2:'X', 3:'9', 4:'8', 5:'7', 6:'6', 7:'5', 8:'4', 9:'3', 10:'2'}  # 最后一位

# regions-->区域代码6位list ; birthdays -->生日yymmdd格式8位list; num-->个数3位int
def get_idCard(regions,birthdays,num):
    idCards = []
    for region in regions:
        for birthday in birthdays:
            for i in range(num):
                idCard = region+birthday+ '%03d'%(i)
                sum = 0
                for i in range(17):
                    sum = sum + int(idCard[i:i + 1]) * weight_code[i]
                Y = sum % 11
                last_code = check_code[Y]
                id_card = idCard + last_code
                idCards.append(id_card)
    return(idCards)


def get_oneCard(birthday):
    idCard = '110101' + birthday + '100'
    sum = 0
    for i in range(17):
        sum = sum + int(idCard[i:i + 1]) * weight_code[i]
    Y = sum % 11
    last_code = check_code[Y]
    id_card = idCard + last_code
    print(id_card)
    return(id_card)


if __name__ == '__main__':
    get_oneCard('19881103')